﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EmployeesSalary_EmpSalaryAdjust : System.Web.UI.Page
{
    #region 字段初始化
    public string GetJBGZ()
    {
        try
        {
            return Math.Round(Convert.ToDecimal(Master.CurrentRow["JBGZ"]), 2).ToString();
        }
        catch
        {
            return "0.00";
        }
    }
    public string GetJXJJ()
    {
        try
        {
           
           return Math.Round(Convert.ToDecimal(Master.CurrentRow["JXJJ"]), 2).ToString();
            
        }
        catch
        {
            return "0.00";
        }
    }
    public string GetGWJT()
    {
        try
        {

            return Math.Round(Convert.ToDecimal(Master.CurrentRow["GWJT"]), 2).ToString();
        }
        catch
        {
            return "0.00";
        }
    }
    public string GetGLBT()
    {
        try
        {
            return Math.Round(Convert.ToDecimal(Master.CurrentRow["GLBT"]), 2).ToString();
        }
        catch
        {
            return "0.00";
        }
    }

    public string GetAjustTime()
    {
        return DateTime.Now.ToString("yyyy-M");
    }
    #endregion


    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();

            

            WMaster.SetWhere("EmpSalaryAdjust.EmployeeId=" + Request["eid"].ToString() + " and EmpSalaryAdjust.AdjustStatus=1");
            Master.DataSource = WMaster;
            ((HiddenField)this.Page.Master.FindControl("HoverId")).Value = "EmpSalary";
            ((HiddenField)EmpSalaryBar.FindControl("HoverId")).Value = "EmpSalaryAdjust";
         

            MasterPage_MasterPage_EmpDetail master = (MasterPage_MasterPage_EmpDetail)this.Page.Master;
         
            master.HelpHref = "";
            master.PageName = "员工薪资调整";
            master.PicUrl = "";
            master.IntiBar();
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EmployeesSalary_EmpSalaryAdjust));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SEmployees.EmpSalaryAdjust";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    public bool ValMoney(object value)
    {
        System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
        return reg1.IsMatch(value.ToString());
    }

    protected void EmpSalaryAdjust_Command(object sender, CommandEventArgs e)
    {

        if (e.CommandName == "cmdFirst" || e.CommandName == "cmdPrevious"
            || e.CommandName == "cmdNext" || e.CommandName == "cmdLast")
        {
            Master.ExecuteSelect(FVSalaryAdjust);
            DataBind();
        }
        else if (e.CommandName == "cmdAdd")
        {
            //Master.ExecuteAdd(Contract);
            DataBind();
        }
        else if (e.CommandName == "cmdDelete")
        {
            Master.ExecuteSelect(FVSalaryAdjust);
            DataBind();
        }
        else if (e.CommandName == "cmdApply" && FVSalaryAdjust.AllValidateSucess)
        {
            Master.ExecuteSelect(FVSalaryAdjust);
            DataBind();
        }
    }

    protected void FVSalaryAdjust_DataBound(object sender, EventArgs e)
    {
        try
        {
            if (Request["action"] != null)
            {
                if (Request["action"].ToString() == "view" || Request["action"].ToString() == "self")
                {
                    wn.Visible = false;
                }
            }

            if (FVSalaryAdjust.CurrentMode == FormViewMode.ReadOnly)
            {
                LitTitle.Text = "当前薪资";
            }
            else if (FVSalaryAdjust.CurrentMode == FormViewMode.Edit)
            {
                LitTitle.Text = "薪资修改";
            }
            else if (FVSalaryAdjust.CurrentMode == FormViewMode.Insert)
            {
                LitTitle.Text = "薪资调整";
            }

            if (Master.CurrentRow != null)
            {
                hidEid.Value = Master.CurrentRow["EmployeeId"].ToString();
                hidEname.Value = Master.CurrentRow["EmpName"].ToString();

            }
            else
            {

                string eid = Request["eid"].ToString();
                object[] oj = Srvtools.CliUtils.CallMethod("SEmployees", "GetEmpNameByEid", new object[] { eid });
                string ename = oj[1].ToString();

                hidEid.Value = eid;
                hidEname.Value = ename;
            }

            Control_SelUser su = FVSalaryAdjust.FindControl("SelUser") as Control_SelUser;
            su.ReadOnly(hidEid.Value, hidEname.Value);
        }
        catch
        {
        }
    }

    protected void Master_Adding(object sender, Srvtools.WebDataSourceAddingEventArgs e)
    {
        try
        {
            Control_SelUser su = FVSalaryAdjust.FindControl("SelUser") as Control_SelUser;
            if (su.EmployeeId == "")
            {
                return;
            }
            else
            {
                e.AddingValues["EmployeeId"] = su.EmployeeId;
                e.AddingValues["EditTime"] = DateTime.Now;
                e.AddingValues["EditEmpId"] = Convert.ToInt32(Srvtools.CliUtils.GetValue("_UserCode")[1]);
                e.AddingValues["AdjustStatus"] = true;
                hidEid.Value = su.EmployeeId;
                hidEname.Value = su.EmpName;

            }
        }
        catch
        {
            return;
        }

    }
    protected void Master_Updating(object sender, Srvtools.WebDataSourceUpdatingEventArgs e)
    {

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmpSalaryAdjustList.aspx?redurl=" + Server.UrlEncode(Request.Url.ToString()) + "&eid=" + Request["eid"].ToString());
    }
}
